package com.hs.bai.controller;

import com.hs.bai.pojo.Expenseinfo;
import com.hs.bai.pojo.Order;
import com.hs.bai.service.IExpenseinfoService;
import com.hs.bai.service.IOrderService;
import com.hs.dto.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 费用信息 前端控制器
 * </p>
 *
 * @author Dingkun Bai
 * @since 2022-06-13
 */
@CrossOrigin
@RestController
@RequestMapping("/expenseinfo")
@Api(tags = "订单价格信息模块")
public class ExpenseinfoController {

    @Autowired
    private IExpenseinfoService expenseinfoService;
    @Autowired
    private IOrderService orderService;

    @PostMapping("/add")
    @ApiOperation("添加订单价格信息")
    public ResultBean addBasicOrderInfo(@RequestBody Expenseinfo expenseinfo){

        System.out.println("expenseinfo = " + expenseinfo);
        if (expenseinfo != null) {
            boolean b = expenseinfoService.save(expenseinfo);
            return b ? ResultBean.OK("添加成功！"):ResultBean.ERROR("添加失败！");
        }
        return ResultBean.ERROR("添加失败！");

    }

    /**
     * 修改价格订单信息
     * @param expenseinfo
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改订单价格信息")
    public ResultBean updateBasicOrderInfo(@RequestBody Expenseinfo expenseinfo){
            boolean b = expenseinfoService.updateById(expenseinfo);
            return b ? ResultBean.OK("修改成功！"):ResultBean.ERROR("修改失败！");
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/find/{id}")
    public ResultBean findById(@PathVariable String id){
        Order order = orderService.getById(id);
        Expenseinfo expenseinfo = expenseinfoService.getById(order.getTFId());
        ResultBean ok = ResultBean.OK();
        ok.setData(expenseinfo);
        return ok;
    }

}
